﻿@model JustBlog.Models.ListViewModel

@{
  var currentPage = ViewContext.RequestContext.HttpContext.Request["p"] != null ? int.Parse(ViewContext.RequestContext.HttpContext.Request["p"]) : 1;
  var totalPages = Math.Ceiling((double)Model.TotalPosts / 10);  
}

@if (currentPage > 1 || currentPage < totalPages)
{
  var p = string.Format("p={0}", currentPage - 1);
  var n = string.Format("p={0}", currentPage + 1);

  if (ViewContext.RouteData.Values["action"].ToString().Equals("search", StringComparison.OrdinalIgnoreCase))
  {
    var s = String.Format("?s={0}", ViewContext.RequestContext.HttpContext.Request.QueryString["s"]);
    p = String.Format("{0}&{1}", s, p);
    n = String.Format("{0}&{1}", s, n);
  }
  else
  {
    p = String.Concat("?", p);
    n = String.Concat("?", n);
  }
  
  <div class="pager">
    <a href="@p" title="Previous" class="previous" style="visibility:@(currentPage > 1 ? "visible" : "collapse")"><< previous</a>
    <a href="@n" title="Next" class="next" style="visibility:@(currentPage < totalPages ? "visible" : "collapse")">next >></a>
  </div>
}